define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/ordergoods/index',
                    add_url: 'order/ordergoods/add',
                    edit_url: 'order/ordergoods/edit',
                    del_url: 'order/ordergoods/del',
                    multi_url: 'order/ordergoods/multi',
                    table: 'order_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle: false,
                showColumns: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        // {field: 'order_id', title: __('Order_id')},
                        {field: 'order.ordersn', title: __('Order.ordersn'),operate:'LIKE'},
                        {field: 'name', title: __('Name'),operate:'LIKE'},
                        // {field: 'gtype_id', title: __('Gtype_id')},
                        {field: 'gtype.title', title: __('Gtype.title'),operate:'LIKE'},
                        {field: 'disrule.title', title: __('Disrule.title'),operate:false},
                        {field: 'disrule.rule', title: __('Disrule.rule'),operate:false},
                        {field: 'price', title: __('Price'), operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                        // {field: 'id', title: __('Id')},
                        // {field: 'order_id', title: __('Order_id')},
                        // {field: 'name', title: __('Name')},
                        // {field: 'gtype_id', title: __('Gtype_id')},
                        // {field: 'dis_id', title: __('Dis_id')},
                        // {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'order.id', title: __('Order.id')},
                        // {field: 'order.openid', title: __('Order.openid')},
                        // {field: 'order.ordersn', title: __('Order.ordersn')},
                        // {field: 'order.agentid', title: __('Order.agentid')},
                        // {field: 'order.price', title: __('Order.price'), operate:'BETWEEN'},
                        // {field: 'order.prepay', title: __('Order.prepay'), operate:'BETWEEN'},
                        // {field: 'order.residue', title: __('Order.residue'), operate:'BETWEEN'},
                        // {field: 'order.discount_id', title: __('Order.discount_id')},
                        // {field: 'order.commission', title: __('Order.commission'), operate:'BETWEEN'},
                        // {field: 'order.status', title: __('Order.status'), formatter: Table.api.formatter.status},
                        // {field: 'order.statis', title: __('Order.statis')},
                        // {field: 'order.createtime', title: __('Order.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'gtype.id', title: __('Gtype.id')},
                        // {field: 'gtype.title', title: __('Gtype.title')},
                        // {field: 'gtype.image', title: __('Gtype.image'), formatter: Table.api.formatter.image},
                        // {field: 'gtype.createtime', title: __('Gtype.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'disrule.id', title: __('Disrule.id')},
                        // {field: 'disrule.title', title: __('Disrule.title')},
                        // {field: 'disrule.rule', title: __('Disrule.rule')},
                        // {field: 'disrule.color', title: __('Disrule.color')},
                        // {field: 'disrule.weigh', title: __('Disrule.weigh')},
                        // {field: 'disrule.createtime', title: __('Disrule.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});